//
//  HomeDetailViewController.m
//  Mahjong
//
//  Created by mc on 16/9/1.
//  Copyright © 2016年 Elliot. All rights reserved.
//

#import "HomeDetailViewController.h"


#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)
static NSString *identifierForGradeCell = @"identifierForGradeCell";
@interface HomeDetailViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, strong) UICollectionView *goodsCollectionView;


@end

@implementation HomeDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
//    self.navigationController.navigationBarHidden = YES;
    
    [self addtopNavleftBtn];
    [self addCollectionView];
}
// 处理导航栏
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

///切换左侧返回按钮的图片
- (void)addtopNavleftBtn {
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] init];
    //initWithImage:[UIImage imageNamed:@"back1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(barbuttonclick:)];
    leftBtn.image = [UIImage imageNamed:@"nav_but_back_xq"];
    leftBtn.style = UIBarButtonItemStyleDone;
    leftBtn.target = self;
    leftBtn.action = @selector(barbuttonclick:);
    self.navigationItem.leftBarButtonItem = leftBtn;
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] init];
    rightBtn.image = [UIImage imageNamed:@"nav_but_collect_pj"];
    rightBtn.style = UIBarButtonItemStyleDone;
    rightBtn.target = self;
    rightBtn.action = @selector(likebuttonclick:);
    
    UIBarButtonItem *fenxiangBtn = [[UIBarButtonItem alloc] init];
    [fenxiangBtn setImage:[UIImage imageNamed:@"nav_but_share_pj"]] ;
    fenxiangBtn.style = UIBarButtonItemStyleDone;
    fenxiangBtn.target = self;
    fenxiangBtn.action = @selector(fenxiangButtonclick:);
    self.navigationItem.rightBarButtonItems = @[rightBtn,fenxiangBtn];
    
}
//返回上一级页面
- (void)barbuttonclick:(UIBarButtonItem *)buttonitem {
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)likebuttonclick:(UIBarButtonItem *)buttonitem{
    
}
-(void)fenxiangButtonclick:(UIBarButtonItem *)buttonitem{
    
}

//-(void)addNav{
//    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, WIDTH, 30)];
//    backView.backgroundColor = [UIColor blackColor];
//    [self.view addSubview:backView];
//    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//    backBtn.frame = CGRectMake(20, 5, 20, 20);
//    [backBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
//    backBtn.backgroundColor = [UIColor clearColor];
//    [backBtn setImage:[UIImage imageNamed:@"nav_but_back_xq"] forState:UIControlStateNormal];
//    backBtn.tag = 2000;
//    backBtn.tintColor = [UIColor whiteColor];
//    [backView addSubview:backBtn];
//    
//    UIButton *likeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//    likeBtn.frame = CGRectMake(WIDTH * 4/ 5, 5, 20, 20);
//    [likeBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
//    likeBtn.backgroundColor = [UIColor clearColor];
//    [likeBtn setImage:[UIImage imageNamed:@"nav_but_collect_pj"] forState:UIControlStateNormal];
//    [likeBtn setImage:[UIImage imageNamed:@"nav_but_collectpre_pjpj"] forState:UIControlStateSelected];
////    if (likeBtn.selected) {
////        NSLog(@"%@",likeBtn.selected);
////        likeBtn.tintColor = [UIColor clearColor];
////        likeBtn.backgroundColor = [UIColor whiteColor];
////    }else{
////        likeBtn.tintColor = [UIColor redColor];
////        likeBtn.backgroundColor = [UIColor clearColor];
////    }
//    
//    likeBtn.tag = 2001;
//    [backView addSubview:likeBtn];
//    
//}
//-(void)btnAction:(UIButton *)button{
//    if (2000 == button.tag) {
//        [self.navigationController popViewControllerAnimated:YES];
//    }else if (2001 == button.tag){
//        button.selected = !button.selected;
//        NSLog(@"likeBton");
//    }
//}
//
-(void)addCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //滚动方向
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //cell大小
    layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width/2 -5, [UIScreen mainScreen].bounds.size.width/2 - 5);
    //最小的行间距
    layout.minimumLineSpacing = 10;
    //cell之间的最小距离
    layout.minimumInteritemSpacing = 10;
    
    //设置区头大小
    layout.headerReferenceSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height *2.3/3);
    //    //设置区尾大小
    //    layout.footerReferenceSize = CGSizeMake(375, 50);
    //设置分区的间距, 不包含区头和区尾, 只影响内容部分的间距
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.goodsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) collectionViewLayout:layout];
    self.goodsCollectionView .delegate = self;
    self.goodsCollectionView .dataSource = self;
    self.goodsCollectionView .backgroundColor = [UIColor colorWithWhite:0.975 alpha:1.000];
    
    [self.view addSubview:self.goodsCollectionView ];
    [self.goodsCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:identifierForGradeCell];
//    [self.goodsCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIndentifier];
    
}
//某个分区的CELL或者是Item的个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 100;
}
//返回cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierForGradeCell forIndexPath:indexPath];
//    cell.firstLabel.text = @"中欧十二;就颇为欧佩克法立法方面是减肥";
//    cell.priceLable.text = @"$1980";
//    cell.salesLable.text = @"销量564";
    
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
//分区个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
#pragma mark -- UICollectionViewDelegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    HomeDetailViewController *homeDetailVC = [[HomeDetailViewController alloc] init];
    [self.navigationController pushViewController:homeDetailVC animated:YES];
    NSLog(@"%@",indexPath);
}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
//    self.navigationController.navigationBarHidden = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
//    self.navigationController.navigationBarHidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
